Skip to content

[Build] Move aapt2 download from xaprepare to MSBuild target#11399

Merged
jonathanpeppers merged 7 commits into
mainfrom
jonathanpeppers/move-aapt2-download-to-msbuild
May 21, 2026
Merged

[Build] Move aapt2 download from xaprepare to MSBuild target#11399
jonathanpeppers merged 7 commits into
mainfrom
jonathanpeppers/move-aapt2-download-to-msbuild

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

@jonathanpeppers jonathanpeppers commented May 18, 2026

Summary

Remove Step_Get_Android_BuildTools from xaprepare and move the aapt2 download/extract logic into src/aapt2/aapt2.targets as a proper MSBuild target.

Changes

The new _DownloadBuildTools target in aapt2.targets:

  • Downloads the 3 platform build-tools zips (macOS, Windows, Linux)
  • Validates hardcoded SHA-256 checksums from Configuration.props (Google's manifest only provides SHA-1, which MSBuild's GetFileHash doesn't support)
  • Uses MSBuild target batching (Outputs="...%(_BuildTools.Identity)") so each platform is processed independently
  • Uses Inputs/Outputs on both _DownloadBuildTools and _ExtractAapt2 for incremental build skip

Removed from xaprepare:

  • Step_Get_Android_BuildTools.cs
  • Step registration from Scenario_Standard.cs
  • BuildToolsArchiveDownloaded property from Context.cs

Cleaned up unused properties:

  • XABuildToolsPackagePrefix and per-platform variants (MacOS/Windows/Linux) from Configuration.props, KnownProperties.cs, Properties.Defaults.cs.in, xaprepare.targets, and AndroidToolchain.cs

Context

Part of the effort to eliminate xaprepare steps in favor of standard MSBuild targets. This makes the build logic easier to understand, debug, and maintain — no custom C# download infrastructure needed.

jonathanpeppers and others added 3 commits May 18, 2026 16:31
Remove Step_Get_Android_BuildTools from xaprepare and move the aapt2
download/extract logic into src/aapt2/aapt2.targets as a proper MSBuild
target.

The new _DownloadBuildTools target:
- Downloads Google's repository2-3.xml manifest
- Dynamically reads SHA-1 checksums via XmlPeek (no hardcoded hashes)
- Downloads the 3 platform build-tools zips
- Validates checksums and errors on mismatch
- Uses Inputs/Outputs for incremental build skip

This removes one more step from xaprepare, moving the logic to a
standard MSBuild target that is easier to understand and maintain.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Refactor _DownloadBuildTools to use target batching via
Outputs="...%(_BuildTools.Identity)" so the target body runs once per
item. This replaces repeated DownloadFile/GetFileHash/Delete/Error
calls with single instances that operate on the batched item.

Also separate manifest download into its own target with a Condition
to skip when all zips already exist.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
These prefix properties were only used by Step_Get_Android_BuildTools
which has been deleted. The property was always empty and served no
purpose for current build-tools versions.

Removed from:
- KnownProperties.cs
- Properties.Defaults.cs.in
- xaprepare.targets
- Configuration.props
- AndroidToolchain.cs (inlined empty prefix away)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers force-pushed the jonathanpeppers/move-aapt2-download-to-msbuild branch from 2b8296c to 3a13b23 Compare May 18, 2026 21:44
jonathanpeppers and others added 3 commits May 19, 2026 10:30
Remove the Condition on _DownloadAndroidManifest that checked whether
zip files exist. When the zips are cached but _DownloadBuildTools
Inputs/Outputs determines they are stale, the manifest target was
being skipped (Exists=true) while _DownloadBuildTools still ran,
causing XmlPeek to fail on the missing manifest file.

The Inputs/Outputs on _DownloadBuildTools already handles the fully-
cached case: if all zips are up-to-date, neither target runs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use Inputs/Outputs on _DownloadAndroidManifest so it skips entirely
when the manifest file exists and is newer than Configuration.props.
This avoids any network requests on incremental builds, unlike
SkipUnchangedFiles which still makes an HTTP round-trip.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
MSBuild GetFileHash only supports SHA-256 and above, but Google SDK
manifest (repository2-3.xml) only provides SHA-1. Switch to hardcoded
SHA-256 hashes in Configuration.props, following the same pattern used
by bundletool (XABundleToolHash).

This simplifies the targets by removing the manifest download target
and XmlPeek logic entirely.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers marked this pull request as ready for review May 20, 2026 13:23
Copilot AI review requested due to automatic review settings May 20, 2026 13:23
@jonathanpeppers
Copy link
Copy Markdown
Member Author

/review

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Android PR Reviewer completed successfully!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the xaprepare step responsible for downloading Android build-tools archives and shifts the aapt2 acquisition flow into the MSBuild-driven src/aapt2/aapt2.targets, aligning more tool bootstrapping with standard MSBuild targets rather than custom xaprepare logic.

Changes:

  • Add an MSBuild _DownloadBuildTools target in aapt2.targets to download build-tools zips and validate them via SHA-256 before extraction.
  • Remove the xaprepare Step_Get_Android_BuildTools step and associated wiring/properties/prefix handling.
  • Add build-tools SHA-256 hash properties to Configuration.props for download validation.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/aapt2/aapt2.targets Adds MSBuild download + SHA-256 validation target and makes extraction depend on it.
Configuration.props Removes unused build-tools URL prefix properties; adds per-OS build-tools SHA-256 hashes.
build-tools/xaprepare/xaprepare/xaprepare.targets Removes generation-time substitutions for removed build-tools prefix properties.
build-tools/xaprepare/xaprepare/Steps/Step_Get_Android_BuildTools.cs Deletes the xaprepare download step implementation.
build-tools/xaprepare/xaprepare/Scenarios/Scenario_Standard.cs Removes the build-tools download step from the standard scenario.
build-tools/xaprepare/xaprepare/ConfigAndData/Dependencies/AndroidToolchain.cs Removes use of the removed build-tools URL prefix property when defining the build-tools component.
build-tools/xaprepare/xaprepare/Application/Properties.Defaults.cs.in Removes default property initialization for deleted build-tools prefix properties.
build-tools/xaprepare/xaprepare/Application/KnownProperties.cs Removes known-property constants for deleted build-tools prefix properties.
build-tools/xaprepare/xaprepare/Application/Context.cs Removes the unused BuildToolsArchiveDownloaded context property.

Comment thread src/aapt2/aapt2.targets
Comment thread Configuration.props
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — Clean migration from xaprepare to MSBuild

1 warning · 1 suggestion · 0 errors

Summary

This is a well-structured migration that replaces the custom Step_Get_Android_BuildTools xaprepare step with a standard MSBuild _DownloadBuildTools target. The new target follows established repo patterns (mirrors _DownloadBinutils in binutils.targets) and is an improvement over the old code — it adds SHA-256 hash verification that the xaprepare step lacked entirely.

The removal is thorough — all references to the deleted step and the now-unused XABuildToolsPackagePrefix* properties have been cleaned up across KnownProperties.cs, Properties.Defaults.cs.in, Context.cs, AndroidToolchain.cs, Scenario_Standard.cs, and xaprepare.targets.

Positive callouts

  • 🔒 The delete-then-error pattern on hash mismatch prevents use of corrupt/tampered downloads
  • ♻️ Proper Inputs/Outputs on _DownloadBuildTools enables incremental skip when files are already cached
  • 🧹 Complete cleanup of vestigial XABuildToolsPackagePrefix* properties (they were all empty strings)

Note on PR description

The description mentions "Dynamically reads SHA-1 checksums via XmlPeek (no hardcoded hashes)" — this appears to describe an earlier iteration. The actual implementation hardcodes SHA-256 hashes in Configuration.props, which is correctly documented in the code comment. Consider updating the description to match.

CI

dotnet-android ✅ passed. Xamarin.Android-PR not yet visible — may still be starting.

Generated by Android PR Reviewer for issue #11399 · ● 3.2M

Comment thread src/aapt2/aapt2.targets Outdated
Comment thread Configuration.props
The target lacked Inputs/Outputs so UnzipDirectoryChildren ran on
every build. Use the cached zip as Input and the extracted aapt2
binary as Output so extraction is skipped when already up-to-date.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label May 20, 2026
@jonathanpeppers jonathanpeppers merged commit 263744a into main May 21, 2026
3 checks passed
@jonathanpeppers jonathanpeppers deleted the jonathanpeppers/move-aapt2-download-to-msbuild branch May 21, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants